﻿package mortal.game.view.market
{
    import Message.Game.*;
    import Message.Public.*;
    import fl.data.*;
    import flash.utils.*;
    import mortal.component.gconst.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;

    public class MktModConfig extends Object
    {
        public static var hasData:Boolean = false;
        public static var dpItemType1:DataProvider;
        public static var dpLevel:DataProvider;
        public static var dpColor:DataProvider;
        public static var dpCareer:DataProvider;
        public static var dpTimeType:DataProvider;
        public static var dpMoneyType:DataProvider;
        public static var arrItemType:Array;

        public function MktModConfig()
        {
            return;
        }// end function

        public static function createData() : void
        {
            var _loc_2:Dictionary = null;
            var _loc_3:Array = null;
            var _loc_4:Array = null;
            var _loc_5:Array = null;
            var _loc_6:Object = null;
            if (hasData)
            {
                return;
            }
            hasData = true;
            arrItemType = [];
            dpItemType1 = new DataProvider();
            var _loc_1:int = 1;
            for each (_loc_2 in MarketConfig.instance.map)
            {
                
                _loc_6 = {label:_loc_2[1].name1, type:_loc_1};
                arrItemType.push(_loc_6);
                _loc_1++;
            }
            dpItemType1.addItems(arrItemType);
            dpTimeType = new DataProvider([{label:EMarketTimeType._EMarketTimeTypeEight + "小时", type:0, timeType:EMarketTimeType._EMarketTimeTypeEight}, {label:EMarketTimeType._EMarketTimeTypeTwentyFour + "小时", type:0, timeType:EMarketTimeType._EMarketTimeTypeTwentyFour}, {label:EMarketTimeType._EMarketTimeTypeFortyEight + "小时", type:0, timeType:EMarketTimeType._EMarketTimeTypeFortyEight}]);
            dpMoneyType = new DataProvider([{label:GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoin), type:0, moneyType:EPriceUnit._EPriceUnitCoin}, {label:GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitGold), type:1, moneyType:EPriceUnit._EPriceUnitGold}]);
            _loc_3 = [{label:"全部等级", type:0, min:0, max:GameConst.PlayerMaxLevel}, {label:"1-9级", type:1, min:1, max:9}, {label:"10-19级", type:2, min:10, max:19}, {label:"20-29级", type:3, min:20, max:29}, {label:"30-39级", type:4, min:30, max:39}, {label:"40-49级", type:5, min:40, max:49}, {label:"50-59级", type:6, min:50, max:59}, {label:"60级以上", type:7, min:60, max:GameConst.PlayerMaxLevel}];
            dpLevel = new DataProvider(_loc_3);
            _loc_4 = [{label:"全部颜色", type:0, color:-1}, {label:"白色", type:1, color:EColor._EColorWhite}, {label:"绿色", type:2, color:EColor._EColorGreen}, {label:"蓝色", type:3, color:EColor._EColorBlue}, {label:"紫色", type:4, color:EColor._EColorPurple}, {label:"橙色", type:5, color:EColor._EColorOrange}, {label:"金色", type:6, color:EColor._EColorGold}];
            dpColor = new DataProvider(_loc_4);
            _loc_5 = [{label:"全部职业", type:0, career:-1}, {label:GameDefConfig.instance.getCarrer(ECareer._ECareerWarrior), type:1, career:ECareer._ECareerWarrior}, {label:GameDefConfig.instance.getCarrer(ECareer._ECareerArcher), type:2, career:ECareer._ECareerArcher}, {label:GameDefConfig.instance.getCarrer(ECareer._ECareerMage), type:3, career:ECareer._ECareerMage}];
            dpCareer = new DataProvider();
            dpCareer.addItems(_loc_5);
            return;
        }// end function

        public static function getdpItemType2(param1:int) : DataProvider
        {
            var _loc_5:* = undefined;
            var _loc_6:Object = null;
            var _loc_2:* = new DataProvider();
            var _loc_3:Array = [];
            var _loc_4:int = 1;
            for each (_loc_5 in MarketConfig.instance.map[param1])
            {
                
                _loc_6 = {label:_loc_5.name2, type:_loc_4, tMarket:_loc_5};
                _loc_3.push(_loc_6);
                _loc_4++;
            }
            _loc_2.addItems(_loc_3);
            return _loc_2;
        }// end function

        public static function getUnitPrice(param1:SMarketItem) : String
        {
            var price:Number;
            var param:int;
            var param2:Number;
            var marketItem:* = param1;
            var dealPrice:* = function (param1:Number) : String
            {
                if (param1 > param)
                {
                    param1 = int(param1);
                }
                else if (param1 < param2)
                {
                    param1 = param2;
                }
                else
                {
                    param1 = int(param1 * 100) / 100;
                }
                return param1.toString();
            }// end function
            ;
            var coinRate:int;
            var goldRate:int;
            param;
            param2;
            if (marketItem.code == EPriceUnit._EPriceUnitCoin)
            {
                if (marketItem.recordType == EMarketRecordType._EMarketRecordSell)
                {
                    price = marketItem.sellPrice / (marketItem.amount / coinRate);
                    return MktModConfig.dealPrice(price) + ":" + coinRate.toString();
                }
                if (marketItem.recordType == EMarketRecordType._EMarketRecordSeekBuy)
                {
                    return marketItem.sellPrice.toString() + ":" + coinRate.toString();
                }
            }
            else if (marketItem.code == EPriceUnit._EPriceUnitGold)
            {
                if (marketItem.recordType == EMarketRecordType._EMarketRecordSell)
                {
                    price = marketItem.sellPrice / marketItem.amount;
                    return MktModConfig.dealPrice(price) + ":" + goldRate.toString();
                }
                if (marketItem.recordType == EMarketRecordType._EMarketRecordSeekBuy)
                {
                    return marketItem.sellPrice.toString() + ":" + goldRate.toString();
                }
            }
            else
            {
                if (marketItem.recordType == EMarketRecordType._EMarketRecordSell)
                {
                    price = marketItem.sellPrice / marketItem.amount;
                    return MktModConfig.dealPrice(price);
                }
                if (marketItem.recordType == EMarketRecordType._EMarketRecordSeekBuy)
                {
                    return marketItem.sellPrice.toString();
                }
            }
            return "";
        }// end function

        public static function getTotalPrice(param1:SMarketItem) : String
        {
            if (param1.recordType == EMarketRecordType._EMarketRecordSell)
            {
                return param1.sellPrice.toString();
            }
            if (param1.code == EPriceUnit._EPriceUnitCoin)
            {
                return (param1.sellPrice * param1.amount / 10000).toString();
            }
            return (param1.sellPrice * param1.amount).toString();
        }// end function

        public static function get BroadcastCost() : int
        {
            return GameConst.MarketBroadcastCost;
        }// end function

        public static function getTax(param1:int, param2:int, param3:Number) : int
        {
            var num:int;
            var time:* = param1;
            var moneyType:* = param2;
            var price:* = param3;
            var getRate:* = function (param1:int) : int
            {
                var _loc_2:int = 1;
                if (param1 == EMarketTimeType._EMarketTimeTypeEight)
                {
                    _loc_2 = 1;
                }
                if (param1 == EMarketTimeType._EMarketTimeTypeTwentyFour)
                {
                    _loc_2 = 2;
                }
                if (param1 == EMarketTimeType._EMarketTimeTypeFortyEight)
                {
                    _loc_2 = 3;
                }
                return _loc_2 * 5;
            }// end function
            ;
            if (moneyType == EPriceUnit._EPriceUnitCoin || moneyType == EPriceUnit._EPriceUnitCoinBind)
            {
                num = Math.ceil(price / 100) * MktModConfig.getRate(time);
            }
            else if (moneyType == EPriceUnit._EPriceUnitGold)
            {
                num = price * 10 * MktModConfig.getRate(time);
            }
            return Math.max(num, GameConst.MarketMinFee);
        }// end function

    }
}
